/*************************************************************************
    > File Name: AccountItem_test_004.cpp
    > Author: skylon
    > Site: blog.csdn.net/tcm_zhangpeng
    > Created Time: 2016年05月15日 星期日 18时28分35秒
 ************************************************************************/

#include"AccountItem.h"
/*
 *	Simulate the user take money process
 *
 */
int main()
{
	ifstream InStream("Account.in");	//	file you want read
	vector<AccountItem> AllItems(100);
	short i;
	short AccountbookCount;
	string AccountNo;
	string AccountPassword;
	double AccountCount;
	bool Found1;
	bool Found2;

	for (i = 0; i < 100; i++)
	{
		AllItems[i].Read(InStream);
		if (InStream.fail() != 0)
			break;
	}
	AccountbookCount = i;

	cout << "Please input AccountNo: " << endl;
	cin >> AccountNo;
	cout << "Please inout AccountPassword: " << endl;
	cin >> AccountPassword;

	Found1 = Found2 = false;
	for (i = 0; i < AccountbookCount; i++)	//	verification the AccountNo and AccountPassword
	{
		if (AccountNo == AllItems[i].GetNumber())
		{
			Found1 = true;
		}
		if (Found1 == true && AccountPassword == AllItems[i].GetPassword())
		{
			Found2 = true;
			break;
		}
	}
	if (Found2 == true)
	{
		cout << "Please input amount of withdrawal: " << endl;
		cin >> AccountCount;
		if (AccountCount <= AllItems[i].GetBalance())	//	
		{
			AllItems[i].DeductBalance(AccountCount);	//	modify
			cout << "Your balance is: " << endl;
			cout << AllItems[i].GetBalance() << endl;
		}
		else
		{
			cout << "Balance is not enough!" << endl;
		}
	}
	else
	{
		if (Found1 == true)
		{
			cout << "wrong password!" << endl;
		}
		else
		{
			cout << "account isn't exist!" << endl;
		}
	}

	return 0;
}
